<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?
  $zone = $request->get("zone", "");
  $instance_id = $request->get("instance_id", "0");
  @chars = $EQW->ListPlayers($zone, $instance_id);
#(
#   { character => "Joe", account => "yay", location_short => "arena", location_long => "Arena" },
#   { character => "Bob", account => "yay", location_short => "freportw", location_long => "West Freeport" },
#   { character => "Monkey", account => "notyay", location_short => "freportn", location_long => "North Freeport" }
#  );
?>
<head>
    <title>EQEmu</title>
    <link rel="stylesheet" type="text/css" href="style/style.css"/>
    <script src="scripts/jquery.js"></script>
    <script>
    <!--
    var zone = <?print "\"$zone\"";?>;
    var instance_id = <?print "\"$instance_id\"";?>;

    var idx = Math.floor((Math.random()*100000000));
    function GetStatusIdx() {
        return idx++;
    }

    function StatusTic() {
        $.getJSON("data/player_data.html?zone="+zone+"&instance_id="+instance_id+"&idx="+GetStatusIdx(),
        function(data) {
            $("#player_table").empty();
            var app_html = "<tr>";
            app_html += "<th scope=\"col\">Character</th>";
            app_html += "<th scope=\"col\">Location</th>";
            app_html += "</tr>";

            var elm = document.getElementById("player_count");
            elm.innerHTML = data.player_count;

            $("#player_table").append(app_html);
            for(var i = 0; i < data.player_count; i++) {
                app_html = "<tr>";

                app_html +=  "<tr id=\"row_$char->{character}\">";
                if(data.players[i].character == "") {
                    app_html +=  "<td>Not Selected</td>";
                } else {
                    app_html +=  "<td>"+data.players[i].character;
                    if(data.players[i].guild_id > 0) {
                        app_html +=  " &lt;"+data.players[i].guild+"&gt;";
                    }
                    app_html +=  "<br>";
                    app_html +=  data.players[i].level + " " + data.players[i].race + " " + data.players[i].class;
                    app_html +=  "</td>";
                }
                app_html +=  "<td>"+data.players[i].location_long+" ("+data.players[i].location_short+")</td>";
                app_html += "</tr>";
                $("#player_table").append(app_html);
            }
        });
    }

    $(document).ready(function() {
        setInterval("StatusTic()", 4000);
    });

    -->
    </script>
</head>
<body>
    <div class="container">
        <?do("templates/scripts/menu_noaccess.pl");?>
        <div id="main_content" class="main">
            <h2 align="center">Online Player List</h2>
            <div align="center">
            <?
            if($zone eq "") {
                print "There are <span id=\"player_count\">".($#chars+1)."</span> players logged in.";
            } else {
                print "There are <span id=\"player_count\">".($#chars+1)."</span> players in $zone.";
            }
            ?>
            </div>
            </br>

            <table id="player_table" width="70%" cellspacing="0" cellpadding="0" class="styled_table">
            <tr>
                <th scope="col">Character</th>
                <th scope="col">Location</th>
            </tr>
                <?
                foreach my $charname (@chars) {
                    my $char = $EQW->GetPlayerDetails($charname);
                    if(!$char) {
                        $char->{character} = "ERROR: no char";
                    } elsif($char->{error}) {
                        $char->{character} = "ERROR: ".$char->{error};
                    }
                    print "<tr id=\"row_$char->{character}\">";
                    if($char->{character} eq "") {
                        print "<td>Not Selected</td>";
                    } else {
                        print "<td>$char->{character}";
                        if(defined($char->{guild_id}) && $char->{guild_id} > 0) {
                            print " &lt;$char->{guild}&gt;";
                        }
                        print "<br>";
                        print "$char->{level} $char->{race} $char->{class}";
                        print "</td>";
                    }
                    print "<td>$char->{location_long} ($char->{location_short})</td>";
                    print "</tr>";
                }
                ?>
            </table>
        </div>
    </div>
    <div class="footer">
        &copy 2012 EQEmu. All rights reserved.
    </div>
</body>
</html>
